package com.atguigui.leetcode;

/**
 * 1475.商品折扣后的最终价格
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/9/1 8:44
 */
public class P1475FinalPricesWithASpecialDiscountInAShop {

    public static void main(String[] args) {
        Solution solution = new P1475FinalPricesWithASpecialDiscountInAShop().new Solution();
        // TO TEST
    }

    class Solution {
        public int[] finalPrices(int[] prices) {
            int[] ans = new int[prices.length];

            for (int i = 0, j = i + 1; i < prices.length; i++) {
                //得到满足条件的最小下标
                int commodityPrice = prices[i];
                boolean flag = true;
                for (int k = j; k < prices.length; k++) {
                    if (prices[k] <= commodityPrice) {
                        ans[i] = commodityPrice - prices[k];
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    ans[i] = commodityPrice;
                }
                j++;
            }


            return ans;
        }
    }
}
